package com.huli.controller;

import com.huli.pojo.SysRole;
import com.huli.service.RoleService;
import com.huli.util.Result;
import com.huli.vo.OrganizationUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;

    // 查询角色表
    @RequestMapping("/roleList")
    public OrganizationUserVo roleList(OrganizationUserVo organizationUserVo){
        return roleService.roleList(organizationUserVo);
    }

    // 根据角色名称查询数据
    @RequestMapping("/roleName")
    public List<SysRole> roleName(String roleName){
        return roleService.roleName(roleName);
    }

    // 修改角色表数据
    @RequestMapping("/updateRole")
    public Result updateRole(SysRole sysRole){
        try {
            roleService.updateRole(sysRole);
            return Result.success("修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("修改失败");
        }
    }

    //

    // 添加角色表数据
    @RequestMapping("/addRole")
    public Result addRole(SysRole sysRole){
        try {
            roleService.addRole(sysRole);
            return Result.success("添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("添加失败");
        }
    }
    @RequestMapping("/selectRoleById")
    public Result selectRoleById(Long id){
        try {
            SysRole sysRole = roleService.selectRoleById(id);
            return Result.success(sysRole);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查询失败");
        }
    }
    @RequestMapping("/deleteRole")
    public Result deleteRole(Long id){
        try {
            roleService.deleteRole(id);
            return Result.success("删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("删除失败");
        }
    }
}
